<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <input type="text" name="" id="input1">

    <script>
        const input1 = document.getElementById('input1')

        input1.onkeydown = function (e) {
            //  默认行为 字符输入
            // if (e.keyCode > 57 || e.keyCode < 48) {
            //     e.preventDefault();
            // }
            if (e.key < 'a' || e.key > 'f') {
                e.preventDefault();
            }
        }

    </script>

</body>

</html>